﻿Imports System.Drawing
Imports System.Reflection

Public Class Pn_PanelGradient
    Dim mStartColor As System.Drawing.Color
    Dim mEndColor As System.Drawing.Color
    Dim _GradientLeftToRight As Boolean
    Dim _StartColorPostion As Integer
    Dim _GradientLabelfont As Font
    Dim _GradientLabelforecolor As Color
    Dim _GradientLabelText As String
    Dim Centrepoint As Integer

    'Protected Overrides Sub OnPaint(ByVal e As System.Windows.Forms.PaintEventArgs)
    '    MyBase.OnPaint(e)
    'End Sub
    Public Property GradientColor1() As System.Drawing.Color
        Get
            Return mStartColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            mStartColor = value
            PaintGradient()
        End Set
    End Property
    Public Property GradientColor2() As System.Drawing.Color
        Get
            Return mEndColor
        End Get
        Set(ByVal value As System.Drawing.Color)
            mEndColor = value
            PaintGradient()
        End Set
    End Property
    Public Property GradientLeftToRight() As Boolean
        Get
            Return _GradientLeftToRight
        End Get
        Set(ByVal value As Boolean)
            _GradientLeftToRight = value
            If _GradientLeftToRight = True Then
                _StartColorPostion = Me.Panel1.Width
            Else
                _StartColorPostion = Me.Panel1.Top
            End If
            PaintGradient()
        End Set
    End Property
    Public Property GradientFont() As Font
        Get
            Return _GradientLabelFont
        End Get
        Set(ByVal value As Font)
            _GradientLabelfont = value
            Change_GradientLabelFont()
        End Set
    End Property
    Public Property GradientForeColor() As Color
        Get
            Return _GradientLabelforecolor
        End Get
        Set(ByVal value As Color)
            _GradientLabelforecolor = value
            Change_GradientLabelForeColor()
        End Set
    End Property
    Public Property GradientHeaderText() As String
        Get
            Return _GradientLabelText
        End Get
        Set(ByVal value As String)
            _GradientLabelText = value
            Change_GrdientLabelText()
        End Set
    End Property
    'Public Property GradientStyle As 
    Sub PaintGradient()
        Try
            Dim gradBrush As New Drawing2D.LinearGradientBrush(New Point(0, 0), New Point(_StartColorPostion, Panel1.Height), GradientColor1, GradientColor2)
            Dim bmp As New Bitmap(Panel1.Width, Panel1.Height)
            Dim g As Graphics = Graphics.FromImage(bmp)
            g.FillRectangle(gradBrush, New Rectangle(0, 0, Panel1.Width, Panel1.Height))
            Panel1.BackgroundImage = bmp
            Panel1.BackgroundImageLayout = ImageLayout.Stretch
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

    End Sub
    Sub Change_GradientLabelFont()
        Me.Label1.Font = _GradientLabelfont

        Centrepoint = (Me.Panel1.Height - Me.Label1.Height) / 2
        Me.Label1.Top = Centrepoint

    End Sub
    Sub Change_GradientLabelForeColor()
        Me.Label1.ForeColor = _GradientLabelforecolor
    End Sub
    Sub Change_GrdientLabelText()
        Me.Label1.Text = _GradientLabelText
    End Sub
    Public Sub New()

        ' This call is required by the Windows Form Designer.
        InitializeComponent()
        mStartColor = Color.CornflowerBlue
        mEndColor = Color.MidnightBlue
        _GradientLeftToRight = False
        _GradientLabelfont = Me.Label1.Font
        _GradientLabelforecolor = Me.Label1.ForeColor
        _GradientLabelText = "Title"
        PaintGradient()
        ' Add any initialization after the InitializeComponent() call.

    End Sub

    Private Sub Panel1_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Panel1.Resize
        Centrepoint = (Me.Panel1.Height - Me.Label1.Height) / 2
        Me.Label1.Top = Centrepoint
    End Sub

    Private Sub Pn_PanelGradient_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Panel1_Paint(ByVal sender As System.Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles Panel1.Paint
        Me.Dock = DockStyle.Top
    End Sub
End Class
